package com.wpen;

import java.util.concurrent.TimeUnit;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;

/**
 * 
 * @author Wang Peng
 * @date 2022-11-22
 */
@SpringBootApplication
@EnableAutoConfiguration
@MapperScan(basePackages = { "com.wpen.unit.infra.mybatis.*.mapper" })
public class UnitJobAdminApplication {

	public static void main(String[] args) {
		SpringApplication.run(UnitJobAdminApplication.class, args);
	}

	@Bean
	RestTemplate restTemplate() {
		OkHttpClient.Builder builder = new OkHttpClient.Builder();
		builder.connectionPool(pool()).connectTimeout(2, TimeUnit.SECONDS).readTimeout(30, TimeUnit.SECONDS)
				.writeTimeout(30, TimeUnit.SECONDS).retryOnConnectionFailure(false);
		
		RestTemplate restTemplate = new RestTemplate(new OkHttp3ClientHttpRequestFactory(builder.build()));
		return restTemplate;
	}

	@Bean
	public ConnectionPool pool() {
		return new ConnectionPool(10, 25, TimeUnit.SECONDS);
	}

}
